package robotleMvc.frameworks.tree
{
	import _Pan3D.display3D.Display3DContainer;
	import _Pan3D.program.Program3DManager;
	import _Pan3D.program.shaders.WillDeleShader;
	
	import flash.display3D.Context3D;
	import flash.display3D.Program3D;
	import flash.events.Event;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	
	import org.robotlegs.mvcs.Mediator;
	
	import robotleMvc.ui.tree.Tree3DSprite;
	import robotleMvc.ui.tree.TreeView;

	public class TreeMediator extends Mediator
	{
		[Inject]
		public var treeView:TreeView
		[Inject]
		public var treeModel:TreeModel


		public function TreeMediator()
		{
			super();
		}

		override public function onRegister():void
		{

			treeModel.display3DContainer=treeView.display3DContainer;
			treeModel.context3D=treeView.context3D;

			loadBuildConfigXml();

		}
		private function loadBuildConfigXml():void
		{
			
			var _loaderURL:URLRequest = new URLRequest("../_File/nijia2/build/"+"treeList.xml");
			var _scenexml:URLLoader=new URLLoader();
			_scenexml.load(_loaderURL);
			_scenexml.addEventListener(Event.COMPLETE, _loadGroundXmlOk);
			function _loadGroundXmlOk(event:Event):void
			{  
				//将XML数据传到MODEL进行解析。
				treeModel.praseTreeXmltoItem(XML(_scenexml.data));
			}
			
		}

		private function addTrees():void
		{

			var display3DSprite:Tree3DSprite=new Tree3DSprite(treeModel.context3D);
			display3DSprite.url="daocao_yewai";
			display3DSprite.x=500;
			display3DSprite.y=0;
			display3DSprite.z=750;
			display3DSprite.scale=10

			treeModel.display3DContainer.addChild(display3DSprite);
			var treeShaderProgram3d:Program3D=Program3DManager.getInstance().getProgram(WillDeleShader.WILL_DELE_SHADER);
			treeModel.display3DContainer.setProgram3D(treeShaderProgram3d);


		}
	}
}
